import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { OrderItemEntity } from './order-item.entity';

@Entity('shop-order')
export class OrderEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true, comment: '订单号' })
  orderNo: string;

  @Column({ comment: '用户id' })
  userId: number;

  @Column('decimal', { precision: 10, scale: 2, comment: '订单总金额' })
  totalAmount: number;

  @Column({ type: 'text', comment: '收货地址快照json' })
  addressSnapshot: string;

  @Column({ default: 'unpaid', comment: '订单状态' })
  status: 'unpaid' | 'paid' | 'cancelled' | 'shipped' | 'completed';

  @OneToMany(() => OrderItemEntity, (orderItem) => orderItem.order, { cascade: true })
  items: OrderItemEntity[];

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;
}
